import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/components/back_btn_icon.dart';
import 'package:share_fit/app/controllers/device/voice/voice_logic.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/app/tools/color_const.dart';
import 'package:share_fit/generated/locales.g.dart';

class VoicePage extends StatelessWidget {

  final logic = Get.put(VoiceLogic());
  final state = Get.find<VoiceLogic>().state;

  @override
  Widget build(BuildContext context) {
    state.switchValue = logic.read("voice_switch", defaultValue: false);
    return Scaffold(
      appBar: AppBar(
        title: Text(LocaleKeys.voice_assistant.ts, style: TextStyle(fontSize: 54.sp, color: ColorConst.btnFontColor),),
        centerTitle: true,
        leading: BackBtnIcon(onTap: () => Get.back()),
        // leading: IconButton(
        //   padding: EdgeInsets.only(left: 15,),
        //   icon: Image.asset("assets/images/space/icon_appbar_arrow_back.png"),
        //   onPressed: () { Get.back(); },
        //   // child: Image.asset("images/icon_appbar_arrow_back.png"),
        // ),
        // leadingWidth: 25,
      ),
      body: Column(
        children: [
          Container(
            height: 58,
            padding: EdgeInsets.only(left: 59.w, right: 59.w),
            margin: EdgeInsets.fromLTRB(43.w, 100.h, 43.w, 39.h),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10),
                color: Colors.white
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(LocaleKeys.voice_assistant_switch.ts, style: TextStyle(fontSize: 42.sp),),
                GetBuilder<VoiceLogic>(
                    id: "voice_switch",
                    builder: (_){
                      return Transform.scale(
                        scale: 0.7,
                        child: CupertinoSwitch(value: state.switchValue,
                          activeColor: ColorConst.activeColor,
                          onChanged: (value){
                            logic.save("voice_switch", value);
                            logic.switchVoice(value);
                          }),);
                    })
              ],
            ),
          ),
          Container(
            width: 1.sw,
            margin: EdgeInsets.only(left: 100.w),
            child: Text(LocaleKeys.voice_assistant_prompt.ts, style: TextStyle(color: ColorConst.btnFontColor, fontSize: 42.sp),),
          )
        ],
      ),
    );
  }
}